package com.xmy.cultivate.service.impl;

import com.xmy.cultivate.constants.MqConstants;
import com.xmy.cultivate.entity.*;
import com.xmy.cultivate.entity.views.IntegralStatisticsRs;
import com.xmy.cultivate.respons.QyWeChartPushRs;
import com.xmy.cultivate.service.IMqPushService;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MqPushServiceImpl implements IMqPushService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void updateStudentClassType(StudentClassType studentClassType){
        try{
            //先发送到erp，Mq添加好帐号，再从erpMq分发给其它系统
            //rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_SYNC_STUDENT_CLASS_TYPE_FANOUT, null, studentClassType);
        }catch (Exception e){
        }
    }

    @Override
    public void updateIsPresortForRecord(Long schoolId, Long studentId, Integer yearPart, Integer quarterNum, Long subjectsId, Integer lessonType){
        try{
            StudentGrade studentGrade = new StudentGrade();
            studentGrade.setYearPart(yearPart);
            studentGrade.setQuarterNum(quarterNum);
            studentGrade.setStudentId(studentId);
            studentGrade.setSubjectsId(subjectsId);
            studentGrade.setLessonType(lessonType);
            //rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_ERP_STUDENT_GRADE_IS_PRESORT_FOR_RECORD_FANOUT, null, studentGrade);
        }catch (Exception e){
        }
    }


    /**
     * 发送多个时间的信息
     * @param multiDelayMessage
     * @param firstDelayNum 多少后秒
     */
    @Override
    public void classUpRemindMulti(MultiDelayMessage<MqSchedulingLog> multiDelayMessage, Integer firstDelayNum){
//        try{
//            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_DELAY_CLASS_REMIND_DIRECT, null, multiDelayMessage, new MessagePostProcessor() {
//                @Override
//                public Message postProcessMessage(Message message) throws AmqpException {
//                    Integer delayNum = 1000 * firstDelayNum;
//                    message.getMessageProperties().setDelay(delayNum);
//                    return message;
//                }
//            });
//        }catch (Exception e){
//        }
    }

    /**
     *
     * @param mqSchedulingLog
     */
    @Override
    public void classUpRemind(MqSchedulingLog mqSchedulingLog){
//        try{
//        rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_DELAY_CLASS_REMIND_DIRECT, null, mqSchedulingLog, new MessagePostProcessor() {
//                @Override
//                public Message postProcessMessage(Message message) throws AmqpException {
//                    Integer delayNum = 1000 * Integer.parseInt(mqSchedulingLog.getDelayedSecond().toString());
//                    message.getMessageProperties().setDelay(delayNum);
//                    return message;
//                }
//            });
//        }catch (Exception e){
//        }
    }

    @Override
    public void integralStatistics(IntegralStatisticsRs integralStatisticsRs){
//        try{
//            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_ERP_INTEGRAL_STATISTICS_FANOUT, null, integralStatisticsRs);
//        }catch (Exception e){
//        }
    }

    /**
     * 更新企业微信号到财务系统
     * @param staff
     */
    @Override
    public void updateQyWecharId(Staff staff){
//        try{
//            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_QY_WECHART_ACCOUNT_FANOUT, null, staff);
//        }catch (Exception e){
//            //System.out.println("out:"+e.getMessage());
//        }
    }

    /**
     * 推送数据到企业微信
     * @param qyWeChartPushRs
     */
    @Override
    public void pushContentForQyWeChar(QyWeChartPushRs qyWeChartPushRs){
//        try{
//            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_QY_WECHART_PUSH_MSG_FANOUT, null, qyWeChartPushRs);
//        }catch (Exception e){
//            //System.out.println("out:"+e.getMessage());
//        }
    }

    @Override
    public void syncIsUpFirst(StudentClassType studentClassType){
//        try{
//            rabbitTemplate.convertAndSend(MqConstants.EXCHANGE_SYNC_IS_UP_FIRST_FANOUT, null, studentClassType);
//        }catch (Exception e){
//            //System.out.println("out:"+e.getMessage());
//        }
    }
}
